const offsetMilliseconds = 7 * 24 * 60 * 60 * 1000

Component({
  data: {
    dateLayerVisible: false,
    curDate: Date.now(),
  },
  properties: {
    value: { type: String },
    title: { type: String },
    placeholder: { type: String },
    minDate: { type: Number, value: Date.now() - offsetMilliseconds },
    maxDate: { type: Number, value: Date.now() + offsetMilliseconds },
  },
  methods: {
    openDateLayer() {
      this.setData({ dateLayerVisible: true })
    },
    onConfirmDateTimePicker(e) {
      this.setData({
        value: wx.utils.formatDateToString(e.detail),
        dateLayerVisible: false,
      })
    },
    closeDateLayer() {
      this.setData({ dateLayerVisible: false })
    },
  },
  lifetimes: {
    attached() {
      if (this.properties.value) {
        this.setData({
          curDate: new Date(this.properties.value).getTime(),
        })
      }
    },
  },
})
